# encoding=utf8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
from ..MessageAnalysis import*
from JT_0200 import JT_0200
myclass=JT_0200()
class JT_0704:
    result = []
    s = ""
    def LogicAisle(self, protocolStr, header):
        # 消息体属性
        header_attribute_id = header[1].split(':')[1]
        s = bin(int(header_attribute_id, 16))
        sub_package = int(s[2:])
        sub_package = str("%016d" % sub_package)
        print(sub_package)
        sub_package = sub_package[2]
        if (sub_package == "0"):
            pass
        else:
            header.append("消息总包数：" + protocolStr[0:4] + '\n')
            header.append("包序号：" + protocolStr[4:8] + '\n')
            protocolStr = protocolStr[8:]
        count = 0
        s = protocolStr[count:count + 4]
        t = int(s, 16)
        print(t)
        count = count + 4
        header.append("数据项个数:" + str(t) + "\n")
        s = protocolStr[count:count + 2]
        header.append("位置数据类型:" + s )
        if s== "00" :
            header.append("正常位置批量汇报" + "\n")
        elif s== "01":
            header.append("盲区补报" + "\n")
        count = count + 2
        for l in range(t):
               ff=l+1
               header.append("\n"+"======第"+str(ff)+"个位置信息======" + "\n")
               s = protocolStr[count:count + 4]
               n = int(s, 16)
               header.append("数据长度：" + str(n) + "\n")
               count = count + 4
               print(s)
               header.append("位置汇报数据体：" + "\n")
               s = protocolStr[count:count + n * 2]
               print (s)
               header.append(s + "\n")
               s= s + "007e"
               myclass.LogicAisle(s,header)
               count=count+n * 2
               header.append("\n"+"======第" + str(ff) + "个位置信息======"+"\n")
        self.result = header
